/*
 * @Author: liu_lizhi
 * @Date: 2021-03-17 19:49:51
 * @LastEditTime: 2021-05-26 08:50:21
 * @Description: 使用安卓端http请求:post,upload,download,getuserinfo
 */
cordova.define("com.jsepc.tpf.cordova.PlatformClient", function(require, exports, module) {
  var exec = require('cordova/exec');

  var PlatformClient = function() {};
 
  //http start
  PlatformClient.prototype.httpRequest = function(requestEntity,successCallback,errorCallback){
      var url = requestEntity.url;
      var params = JSON.stringify(requestEntity.data)
      console.log('data' + params)
      console.log('url' + url)
      exec(successCallback, errorCallback, "PlatformClient", "request", [url, params]);
  }
  PlatformClient.prototype.fileUpload = function(requestEntity,successCallback,errorCallback){
      // 上传 文件地址，文件uuid, 文件参数(来源)
      var filePath = requestEntity.filePath;
      var fileUuid = requestEntity.fileUuid;
      var sourceType = requestEntity.sourceType;
      exec(successCallback, errorCallback, "PlatformClient", "upload", [fileUuid, filePath, sourceType]);
  }
  PlatformClient.prototype.fileDownload = function(requestEntity,successCallback,errorCallback){
    //下载，提供uuid，及文件名，文件下载地址（或类型）
    var fileUuid = requestEntity.fileUuid;
    var downPath = requestEntity.downPath;
    var fileName = requestEntity.fileName;
    exec(successCallback, errorCallback, "PlatformClient", "download", [fileUuid, downPath, fileName]);
  }
  //http end
  PlatformClient.prototype.setSubstationInfo = function (orgData, substationData, successCallback, errorCallback) {
    // 设置android主界面班组、变电站信息
    // 班组、变电站信息
    var orgId = orgData.id
    var orgName = orgData.orgName
    var subId = substationData.id
    var subName = substationData.subName
    exec(successCallback, errorCallback, "PlatformClient", "setSubstationForJs", [orgId, orgName, subId, subName]);
  }
  PlatformClient.prototype.getPicture = function (successCallback, errorCallback) {
    // 获取班组信息
    exec(successCallback, errorCallback, "PlatformClient", "getPicture", []);
  }
  PlatformClient.prototype.takePhoto = function (successCallback, errorCallback) {
    // 获取班组信息
    exec(successCallback, errorCallback, "PlatformClient", "takePhoto", []);
  }
  PlatformClient.prototype.getDefaultOrg = function(successCallback,errorCallback){
    // 获取班组信息
    exec(successCallback, errorCallback, "PlatformClient", "getDefaultOrg", []);
  }
  PlatformClient.prototype.getDefaultSubstation = function (successCallback, errorCallback) {
    // 获取变电站信息
    exec(successCallback, errorCallback, "PlatformClient", "getDefaultSubstation", []);
  }
  PlatformClient.prototype.getUserInfo = function (successCallback, errorCallback) {
    // 获取用户信息
    exec(successCallback, errorCallback, "PlatformClient", "getUserInfo", []);
  }
  PlatformClient.prototype.getApkVersion = function(successCallback,errorCallback){
    // 获取当前安卓版本
    exec(successCallback, errorCallback, "PlatformClient", "getApkVersion", []);
  }
  
  PlatformClient.prototype.goHome = function (successCallback, errorCallback) {
    // 返回主界面
    exec(successCallback, errorCallback, "PlatformClient", "goHomePage", []);
  }
  
  var platformClient = new  PlatformClient();
  module.exports=platformClient;
});
